home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / Interfaces&Libraries / Interfaces / CIncludes / XCOFF.h < prev    next >
Encoding:
Text File  |  1997-01-17  |  48.6 KB  |  966 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3.     XCOFF.h
  4.     Definitions of constants and types used to read and
  5.         write object files in the XCOFF format.
  6.  
  7.     Copyright Apple Computer,Inc.  1996
  8.     All rights reserved
  9.  
  10. ************************************************************
  11.  
  12.  This header defines the entire XCOFF file layout. It is based on the PowerOpen Application
  13.  Binary Interface document and the IBM AIX headers. The field names are generally the same
  14.  but others are introduced for PowerPC enhancements or where it makes sense to do so.  
  15.  
  16.  Many of the names are generally the same as those described in
  17.  "Understanding and Usign COFF", A Nutshell Handbook, by O'Reilly & Associates.
  18.  
  19.  Here's a diagram of an XCOFF file described by this header:
  20.  
  21.                                                                             XCOFF File Format
  22.  
  23.                  Composite Header     |-------------------------------|
  24.                                                           |          File Header          |   20 bytes
  25.                                                           |...............................|
  26.                                                           |  Auxiliary Header (optional)  |
  27.                                                           |_______________________________|
  28.                 .text, .data, .bss,   |        Section header 1       |   40 bytes/header
  29.                 .loader, .debug,      |...............................|
  30.                 .except, .typchk      |             _ _ _             |
  31.                 .info, .pad, .ovrflo  |...............................|
  32.                                                           |        Section header N       |
  33.                                                           |_______________________________|
  34.                  "Raw data" is actual |       Raw data section 1      |
  35.                  data corresponding   |...............................|
  36.                  to section headers   |             _ _ _             |
  37.                                       |...............................|
  38.                                       |       Raw data section N      |
  39.                                       |_______________________________|
  40.                                                     |   Relocation data section 1   |   10 bytes/entry
  41.                                       |...............................|
  42.                  Linker (optional)      |             _ _ _             |
  43.                                                           |...............................|
  44.                                                           |   Relocation data section N   |
  45.                                                           |_______________________________|
  46.                  Debugging (optional) |       Line number data 1      |   6 bytes/entry
  47.                                                           |...............................|
  48.                                                           |             _ _ _             |
  49.                                                           |...............................|
  50.                                                           |       Line number data N      |
  51.                                                           |_______________________________|
  52.                                                           |    Symbol Table (optional)    |   18 bytes/entry
  53.                  (optional)           |_______________________________|
  54.                                                           |  String Table (symbol spill)  |
  55.                                                           |_______________________________|
  56.  
  57.  Notes: [1] Only the information to support XCOFF is defined.  XCOFF is derived from COFF,
  58.                          but all (well, most) of the possible stuff defined for COFF that is not used
  59.                         in XCOFF has been omitted.
  60.              
  61.                  [2] In general, all field names are the same as defined in the sources mentioned 
  62.                          earlier for compatibility.  The main struct/union names, however, have been
  63.                         changed to something "more readable".  One naming convention used is that
  64.                         struct/union names of the form "...Entry" (i.e., names suffixed with "Entry")
  65.                         imply that the definition is for one entry of an array of such entries.
  66.                         Additional typedefs have also been added for the "old" names for compatibility
  67.                         with COFF, AIX, PowerOpen.  There is one caution, however.  The names of the
  68.                         various structs are defined as typedefs and NOT as "struct name".   Therefore
  69.                         definitions of the form like "struct AUXENT x;" must be changed to "AUXENT x",
  70.                         or even better, "AuxEntry x".
  71.                         
  72.                 [3] Macros are defined to allow "simpler" access to ALL fields that occur inside
  73.                          of unions or nested structs.  It is ASSUMED all fields are accessed by their
  74.                         simple field names, letting the macros do the extra qualifications.  If the
  75.                         fields are accessed any other way, then the pertinent macros MUST be #undef'ed.
  76.                         
  77.                 [4] All but two field names are unique and pose no compatibility problems using the
  78.                         macros to access them.  The two fields that do conflict are:
  79.                         
  80.                             (1). x_scnlen in the x_csect and x_scn layouts of an AuxEntry.
  81.                                      
  82.                                      These both have the SAME offset within their respective layouts. Thus
  83.                                      the macro defines the qualifiers for only one (x_scn) since accessing
  84.                                      the x_csect or the x_scn will yield the appropriate (correct) value.
  85.                                      
  86.                             (2). l_symndx in the LdrRelEntry layout of a .loader section and in the
  87.                                      line number LineNbrEntry layout.
  88.                                      
  89.                                      These have DIFFERENT offsets and one of them has to be renamed.  Since
  90.                                      the .loader section is for XCOFF and line numbers are in both XCOFF and
  91.                                      COFF, then, for maximum (oldest) compatibility, the LdrRelEntry field
  92.                                      has been renamed to l_symindx (with an inserted "i").
  93.                         
  94.                 [5] Bit numbering is left-to-right (i.e., the IBM way), with bit 0 being the high
  95.                       order bit.  This is important only in the comments which reference bit ranges
  96.                         using the notation "x:y".
  97.                         
  98.                 [6] Some fields have been changed from signed to unsigned since that's the way they
  99.                         are used.  This was done to be more portable and also to say what we REALLY
  100.                         mean.  Related to this, corresponding constant definitions for unsigned fields
  101.                         have been explicity suffixed with the "U", e.g., "0x123U".
  102.                 
  103.                 [7] There is only ONE XCOFF header in this implementation, i.e., this file, XCOFF.h.
  104.                         Standard [X]COFF headers break the various sections up into separate headers.
  105.                         
  106.                 [8] If you are viewing this file from Mac MPW, the markers are set to conveniently
  107.                         allow moving to any part of the definitions.
  108.                         
  109.                 [9] For all other systems, the file is formatted with the assumed tab setting of
  110.                       2.  View this file with that setting for best readability.
  111. */
  112.  
  113. #ifndef __XCOFF__
  114. #define __XCOFF__
  115.  
  116. #include    <ConditionalMacros.h>
  117.  
  118. #if GENERATINGPOWERPC
  119. #pragma options align=mac68k
  120. #endif
  121.  
  122. /* There are macros defined here that use offsetof() and strlen(), therefore...                    */
  123.  
  124. #include <stddef.h>
  125. #include <string.h>
  126.  
  127. /*             To view this file properly, tab stops should be set to 2.                                */
  128.  
  129. /*--------------------------------------------------------------------------------------*/
  130.  
  131.                                                             /*-------------*
  132.                                                              | File Header |
  133.                                                              *-------------*/
  134.  
  135. struct FileHdr {                                                    /* File header layout:                                                */
  136.     unsigned short    f_magic;                                /*         magic number ==> target machine                    */
  137.     unsigned short    f_nscns;                                /*         number of sections (rel. 1)                            */
  138.     long                        f_timdat;                                /*         time and date of file creation                    */
  139.     long                        f_symptr;                                /*         file offset to start of symbol table        */
  140.     long                        f_nsyms;                                /*         number of symbol table entries                    */
  141.     unsigned short    f_opthdr;                                /*         sizeof(optional aux hdr, 0 if omitted)    */
  142.     unsigned short    f_flags;                                /*         flags                                                                         */
  143. };                                                                                /*                  (20-byte header)                            */
  144. typedef struct FileHdr FileHdr, *FileHdrPtr;
  145.  
  146.                                                                                     /* f_magic magic numbers:                                            */
  147. #define    U802TOCMAGIC 0x1DFU                                /*             PowerPC (readonly text segs and TOC)    */
  148. #define    U802WRMAGIC     0x1D8U                                /*             IBM R2  (writeable text segments)            */
  149. #define    U802ROMAGIC     0x1DDU                                /*             IBM R2  (readonly sharable text segs)    */
  150. #define    U800WRMAGIC     0x198U                                /*             IBM RT    (writeable text segments)            */
  151. #define    U800ROMAGIC     0x19DU                                /*             IBM RT    (readonly sharable text segs)    */
  152. #define    U800TOCMAGIC 0x19FU                                /*             IBM RT    (readonly text segs and TOC)    */
  153. #define    X386MAGIC         0x14CU                                /*            x86                                                                        */
  154.  
  155.                                                                                     /* f_flags file header flags:                                    */
  156. #define    F_RELFLG    0x0001U                                    /*         relocation info removed from file                */
  157. #define    F_EXEC        0x0002U                                    /*         executable file                                                    */
  158. #define    F_LNNO        0x0004U                                    /*         line numbers removed from file                    */
  159. #define    F_LSYMS        0x0008U                                    /*         local symbols removed from file                    */
  160. #define F_MINIMAL    0x0010U                                    /*        <reserved>                                                            */
  161. #define    F_UPDATE    0x0020U                                    /*        <reserved>                                                            */
  162. #define F_SWABD        0x0040U                                    /*        <reserved>                                                            */
  163. #define    F_AR16WR    0x0080U                                    /*         <reserved>                                                            */
  164. #define    F_AR32WR    0x0100U                                    /*         32-bit word reversed byte ordering (x86)*/
  165. #define    F_AR32W        0x0200U                                    /*         32-bit word byte ordering (i.e.,PowerPC)*/
  166. #define    F_PATCH        0x0400U                                    /*        <reserved>                                                            */
  167. #define    F_DYNLOAD    0x1000U                                    /*         file dynamically loadable and executable*/
  168. #define    F_SHROBJ    0x2000U                                    /*         file is shared object (shared library)    */
  169.  
  170. typedef FileHdr filehdr;                                     /* for compatibility only                                            */
  171. typedef FileHdr FILHDR;
  172. #define FILHSZ sizeof(FileHdr)
  173.  
  174. struct OptAuxHdr {                                                /* Optional auxiliary header layout:                    */
  175.     short                    o_mflag;                                    /*         flags - how to execute (always 0x010B)    */
  176.     short                    o_vstamp;                                    /*         format version (currently 0x0001)                */
  177.     long                    o_tsize;                                    /*         .text byte size (padded to mult. of 4)    */
  178.     long                    o_dsize;                                    /*         .data byte size (padded to mult. of 4)    */
  179.     long                    o_bsize;                                    /*         .bss  byte size (padded to mult. of 4)    */
  180.     long                    o_entry;                                    /*         virtual address of entry pt. funct desr */
  181.     unsigned long    o_text_start;                            /*        base address of .text section                        */
  182.     unsigned long    o_data_start;                            /*         base address of .data section                        */
  183.                                                                                     /*    ------ System Loader Extensions ------    */
  184.     unsigned long    o_toc;                                        /*         virtual address of TOC anchor                        */
  185.     short                    o_snentry;                                /*         section number containing entry point        */
  186.     short                    o_sntext;                                    /*         section number containing the text            */
  187.     short                    o_sndata;                                    /*         section number containing the data            */
  188.     short                    o_sntoc;                                    /*         section number containing the toc                */
  189.     short                    o_snloader;                                /*         section number containing loader info        */
  190.     short                    o_snbss;                                    /*         section number describing the bss                */
  191.     short                    o_algntext;                                /*         log (base 2) max alignment for .text        */
  192.     short                    o_algndata;                                /*         log (base 2) max alignment for .data        */
  193.     union {                                                                    /*        module type field:                                            */
  194.         unsigned char     o_modtype[2];                    /*                 '1R', 'RE', 'RO'                                        */
  195.         unsigned short o_moduletype;                    /*            more usable way to use o_modtype        */
  196.     } _o_modtype;
  197.     union {                                                                    /*         resultant executable CPU type ID:                */
  198.         unsigned char     o_cputype[2];                     /*                 cpu type info and ID                                */
  199.         struct {                                                            /*                two fields of the o_cputype:                */
  200.             unsigned char o_typeInfo;                        /*                        cpu type characteristic info        */
  201.             unsigned char o_cpuID;                            /*                         cpu type ID                                            */
  202.         } _o;
  203.     } _o_cputype;
  204.     unsigned long    o_maxstack;                                /*         max stack size (bytes) allowed                     */
  205.     unsigned long    o_maxdata;                                /*         max data size (bytes) allowed                     */
  206.     unsigned long    o_resv2[3];                                /*         <reserved>                                                            */
  207. };
  208. typedef struct OptAuxHdr OptAuxHdr, *OptAuxHdrPtr;
  209.  
  210. #define o_modtype      _o_modtype.o_modtype
  211. #define o_moduletype _o_modtype.o_moduletype
  212. #define o_cputype         _o_cputype.o_cputype
  213. #define o_typeInfo     _o_cputype._o.o_typeInfo
  214. #define o_cpuID             _o_cputype._o.o_cpuID
  215.  
  216. #define magic           o_mflag                                /* for compatibility only                                            */
  217. #define    vstamp          o_vstamp
  218. #define    tsize           o_tsize
  219. #define    dsize           o_dsize
  220. #define    bsize           o_bsize
  221. #define    entry           o_entry
  222. #define    text_start o_text_start
  223. #define    data_start o_data_start
  224.                                                                                     /* o_mflag magic numbers:                                            */
  225. #define MFLAG_PAGED        0x010B                            /*        text & data aligned and may be paged        */
  226. #define MFLAG_RO            0x0108                            /*        text is R/O, data in next section                */
  227. #define MFLAG_CONTIG    0x0107                            /*        text & data contiguous, both writable        */
  228.  
  229. #define VSTAMP_FMT_VER         1                            /* o_vstamp format version number                            */
  230.  
  231. #define ModTypeSingleUse (('1'<<8U)|'L')    /* o_modtype module types: single use ('1L')     */
  232. #define ModTypeReusable  (('R'<<8U)|'E')    /*                                                 reusable        ('RE')     */
  233. #define ModTypeReadOnly  (('R'<<8U)|'O')    /*                                                 read only    ('RO')     */
  234.  
  235.                                                                                     /* o_cputype's o_typeInfo cpu type info:            */
  236. #define OTYP_ONETYPE      0x80U                            /*         obj's are ALL of the same type (ID)            */
  237. #define OTYP_COMTYPE      0x40U                            /*        obj's have common intersection of instr.*/
  238. #define OTYP_EMUTYPE      0x20U                            /*        some obj's require emulation                        */
  239.  
  240.                                                                                     /* o_cputype's o_cpuID cpu type ID:                        */
  241.                                                                                     /* (also used by SymTblEntry's n_type n_cpuID)*/
  242. #define CPU_ID_INV          0U                                    /*        not used (invalid ID)                                        */
  243. #define CPU_ID_PPC32     1U                                    /*        32-bit PowerPC                                                    */
  244. #define CPU_ID_PPC64     2U                                    /*        64-bit PowerPC                                                    */
  245. #define CPU_ID_PWRPPC  3U                                    /*        common intersection of PowerPC and Power*/
  246. #define CPU_ID_PWR         4U                                    /*        Power                                                                        */
  247. #define CPU_ID_ANY          5U                                    /*        any                                                                            */
  248. #define CPU_ID_PPC601  6U                                    /*        601                                                                            */
  249. #define CPU_ID_PPC603  7U                                    /*        603                                                                            */
  250. #define CPU_ID_PPC604  8U                                    /*        604                                                                            */
  251. #define CPU_ID_PPC620  9U                                    /*        620                                                                            */
  252.  
  253. typedef OptAuxHdr aouthdr;                                /* for compatibility only                                            */
  254. typedef OptAuxHdr AOUTHDR;                                
  255.  
  256. #define AOUBASICSZ offsetof(OptAuxHdr, o_toc) /* size of basic (COFF) aux header                */
  257. #define AOUTHSZ          sizeof(OptAuxHdr)
  258.  
  259. /* Note: all section numbers are relative to 1.                                                                                    */
  260.  
  261. struct XCOFFHdr {                                                    /* Full XCOFF header layout:                                    */
  262.     FileHdr        fileHdr;                                            /*         file header                                                            */
  263.     OptAuxHdr    aoutHdr;                                            /*         optional auxiliary header                                */
  264. };
  265. typedef struct XCOFFHdr XCOFFHdr, *XCOFFHdrPtr;
  266.  
  267. typedef XCOFFHdr xcoffhdr;                                /* for compatibility only                                            */
  268.  
  269. /*--------------------------------------------------------------------------------------*/
  270.  
  271.                                                                 /*-----------------*
  272.                                                                  | Section Headers |
  273.                                                                  *-----------------*/
  274.  
  275. struct SectionHdrEntry {                                    /* Section header entry layout:                                */
  276.     char                     s_name[8];                                /*         section name (8-char name has NO null!)    */
  277.     union {                                                                    /*         alt meaning if s_type = STYP_OVRFLO            */
  278.         unsigned long s_paddr;                                /*                 physical address                                        */
  279.         unsigned long s_ovrflo_nreloc;                /*                nbr of reloc. entries (STYP_OVRFLO)    */
  280.     } _s_paddr;
  281.     union {                                                                    /*        alt meaning if s_type = STYP_OVRFLO            */
  282.         unsigned long    s_vaddr;                                /*                 virtual addr (= s_paddr)                        */
  283.         unsigned long s_ovrflo_nlnno;                    /*                nbr of line nbr entries(STYP_OVRFLO)*/
  284.     } _s_vaddr;
  285.     unsigned long     s_size;                                    /*         raw data size (bytes)                                        */
  286.     long                     s_scnptr;                                /*         file offset to the raw data (or 0)            */
  287.     long                     s_relptr;                                /*         file offset to relocation entries (or 0)*/
  288.     long                     s_lnnoptr;                                /*         file offset to line nbr entries (or 0)    */
  289.     union {                                                                    /*        alt meaning if s_type = STYP_OVRFLO            */
  290.         unsigned short s_nreloc;                            /*                 nbr of relocation entries                     */
  291.         unsigned short s_nreloc_primary;            /*                sctn nbr of primary overflowing sctn*/
  292.     } _s_nreloc;                                                        /*                (section numbers are relative to 1)    */
  293.     union {                                                                    /*        alt meaning if s_type = STYP_OVRFLO            */
  294.         unsigned short s_nlnno;                                /*                 nbr of line number entries                     */
  295.         unsigned short s_nlnno_primary;                /*                sctn nbr of primary overflowing sctn*/
  296.     } _s_nlnno;
  297.     union    {                                                                    /*        only low-order 16-bits of flags used        */
  298.         unsigned long s_flags;                                /*                 flags                                                                */
  299.         struct {                                                            /*                flags as two 16-bit values:                    */
  300.             unsigned short s_unused;                        /*                        not used                                                */
  301.             unsigned short s_type;                            /*                        section type (see below)                */
  302.         } _s_s;
  303.     } _s;
  304. };
  305. typedef struct SectionHdrEntry SectionHdrEntry, *SectionHdrEntryPtr;
  306.  
  307. #define s_paddr                      _s_paddr.s_paddr
  308. #define s_ovrflo_nreloc        _s_paddr.s_ovrflo_nreloc
  309. #define s_vaddr                      _s_vaddr.s_vaddr
  310. #define s_ovrflo_nlnno        _s_vaddr.s_ovrflo_nlnno
  311. #define s_nreloc                     _s_nreloc.s_nreloc
  312. #define s_nreloc_primary     _s_nreloc.s_nreloc_primary
  313. #define s_nlnno_primary        _s_nlnno.s_nlnno_primary
  314. #define s_nlnno                         _s_nlnno.s_nlnno
  315. #define s_flags                      _s.s_flags
  316. #define s_unused                      _s._s_s.s_unused
  317. #define s_type                          _s._s_s.s_type
  318.  
  319. #define _TEXT                ".text"                                /* names for special sections...                            */
  320. #define _DATA                ".data"
  321. #define _BSS                ".bss"
  322. #define    _PAD                ".pad"
  323. #define _LOADER         ".loader"
  324. #define _TYPCHK         ".typchk"
  325. #define _DEBUG            ".debug"
  326. #define _EXCEPT            ".except"
  327. #define _OVRFLO            ".ovrflo"
  328. #define _EXPORT            ".export"
  329. #define _IMPORT          ".import"
  330. #define _INTERN          ".intern"
  331. #define _SEGMENT         ".segment"
  332.                                                                                     /* s_flags/s_type section types:                            */
  333. #define STYP_REG        0x0000U                                /*         <reserved>: allocated, relocated, loaded*/
  334. #define STYP_DSECT    0x0001U                                /*         <reserved>:!allocated, relocated,!loaded*/
  335. #define STYP_NOLOAD    0x0002U                                /*         <reserved>: allocated, relocated,!loaded*/
  336. #define STYP_GROUP    0x0004U                                /*         <reserved>                                                            */
  337. #define STYP_PAD        0x0008U                                /*         pad:            !allocated,!relocated, loaded*/
  338. #define STYP_COPY        0x0010U                                /*        <reserved>: allocated,!relocated, loaded*/
  339. #define    STYP_TEXT        0x0020U                                /*         text only:  allocated, relocated, loaded*/
  340. #define STYP_DATA        0x0040U                                /*         data only:  allocated, relocated, loaded*/
  341. #define STYP_BSS        0x0080U                                /*         bss only:   allocated,!relocated,!loaded*/
  342. #define STYP_EXCEPT    0x0100U                                /*         exception: !allocated,!relocated,!loaded*/
  343. #define STYP_INFO        0x0200U                                /*        comment:     !allocated,!relocated,!loaded*/
  344. #define STYP_OVER        0x0400U                                /*         <reserved>:!allocated, relocated,!loaded*/
  345. #define STYP_LIB        0x0800U                                /*         <reserved>: = STYP_INFO                                    */
  346. #define STYP_LOADER    0x1000U                                /*         loader                                                                    */
  347. #define STYP_DEBUG    0x2000U                                /*         debug                                                                        */
  348. #define STYP_TYPCHK    0x4000U                                /*         type-check                                                             */
  349. #define STYP_OVRFLO    0x8000U                                /*         relocation and line nbr overflow                 */
  350.  
  351. typedef SectionHdrEntry scnhdr;                        /* for compatibility only                                            */
  352. typedef SectionHdrEntry SCNHDR;
  353. #define    SCNHSZ sizeof(SectionHdrEntry)
  354.  
  355. /*--------------------------------------------------------------------------------------*/
  356.  
  357.                                                          /*-------------------*
  358.                                                             | Raw Data Sections |
  359.                                                             *-------------------*/
  360. /*----------------*
  361.  | Loader section |
  362.  *----------------*
  363.  
  364.  The following is a diagram of the loader section.  The identifiers are the various fields
  365.  defined in the loader header.
  366.  
  367.                                                               Loader Section Format
  368.                                                   
  369.  s_scnptr ------------------> |-------------------------------|
  370.         |        |        |       |     Loader Section Header     | 32 bytes
  371.         |        |        |       |_______________________________|
  372.         |        |        |       |   External symbol [1]         | 24 bytes/entry
  373.         |        |        |       |...............................|
  374.         |        |        |       |             _ _ _             |
  375.         |        |        |       |...............................|
  376.         |        |        |       |   External symbol [l_nsyms]   |
  377.         |        |        |       |_______________________________|
  378.         |        |        |       |  Relocation entry [1]         | 12 bytes/entry
  379.         |        |        |       |...............................|
  380.         |        |        |       |             _ _ _             |
  381.         |        |        |       |...............................|
  382.     s_size     |        |       |  Relocation entry [l_nreloc]  |
  383.         |        |       ---      |_______________________________|    ---
  384.         |        |    l_impoff    |   Import file ID [0]          |     |
  385.         |        |                     |...............................|     |
  386.         |        |                |             _ _ _             | l_istlen
  387.         |        |                |...............................|     |
  388.         |        |                |  Import file ID [l_nimpid-1]  |     |
  389.         |       ---               |_______________________________|    ---
  390.         |     l_stoff             |     String table entry 1      |     |
  391.         |                         |...............................|     |
  392.         |                         |             _ _ _             |  l_stlen
  393.         |                         |...............................|     |
  394.       |                         |     String table entry n      |     |
  395.      ---                        |_______________________________|    ---
  396. */
  397.  
  398. struct LdrHdr {                                                        /* Loader raw data section header layout:            */
  399.     long                    l_version;                                /*         version number (currently 1)                        */
  400.     long                    l_nsyms;                                    /*         nbr of external symbol tbl entries            */
  401.     long                    l_nreloc;                                    /*         nbr of relocation table entries                 */
  402.     unsigned long    l_istlen;                                    /*         length of import file IDs                                 */
  403.     long                    l_nimpid;                                    /*         nbr of import file IDs                                    */
  404.     unsigned long    l_impoff;                                    /*         offset to start of import file IDs            */
  405.     unsigned long    l_stlen;                                    /*         length of the loader string table                */
  406.     unsigned long    l_stoff;                                    /*         offset to start of loader string table     */
  407. };                                                                                /*        (offsets are from loader section start)    */
  408. typedef struct LdrHdr LdrHdr, *LdrHdrPtr;
  409.  
  410. #define LDRHDRVER 1L                                            /* Loader section version number                            */
  411.  
  412. typedef LdrHdr ldhdr;                                            /* for compatibility only                                            */
  413. typedef LdrHdr LDHDR;
  414. #define    LDHDRSZ    sizeof(LdrHdr)
  415.  
  416. #define SYMNMLEN 8                                                /* number of characters in (small) symbol name*/
  417.  
  418. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  419.  
  420. struct LdrExtSymEntry {                                        /* Loader external symbol table entry layout:    */
  421.     union {                                                                    /*    (note: these entries accessed by index)    */
  422.         char                _l_name[SYMNMLEN];                /*         symbol name unless 1st 4 bytes are 0s        */
  423.         struct {                                                            /*         _l_name value if 1st 4 bytes are 0s:        */
  424.             long    _l_zeroes;                                        /*                 the 0s imply use the 2nd 4 bytes        */
  425.             long    _l_offset;                                        /*                 ldr strtbl offset to symbol(not len)*/
  426.         } _l_l;                                                                /*                (offset from start of ldr str tbl)    */
  427.         char        *_l_nptr[2];                                    /*         yet another way to look at the symbol         */
  428.     } _l;
  429.     unsigned long    l_value;                                    /*         address value set by Linker                            */
  430.     short                    l_scnum;                                    /*         1-rel sctn nbr where symbol is defined    */
  431.     unsigned char    l_smtype;                                    /*         symbol type (see below)                                    */
  432.     unsigned char    l_smclas;                                    /*         storage mapping class    (XMC_xx)                    */
  433.     long                    l_ifile;                                    /*          import file ID (0-rel) index(0 not used)*/
  434.     long                    l_parm;                                        /*         ldr sctn relative offset to type chk str*/
  435. };
  436. typedef struct LdrExtSymEntry LdrExtSymEntry, *LdrExtSymEntryPtr;
  437.  
  438. #define    l_name        _l._l_name
  439. #define    l_zeroes    _l._l_l._l_zeroes
  440. #define    l_offset    _l._l_l._l_offset
  441. #define    l_nptr        _l._l_nptr[1]
  442.  
  443. #if 0                                                                            /* l_scnum special section numbers:                        */
  444. #define    N_UNDEF           0                                            /*        undefined or uninited external symbol        */
  445. #define    N_ABS             -1                                            /*         absolute symbol value                                      */
  446. #define    N_DEBUG         -2                                            /*         special debugging symbol (no value)            */
  447. #endif
  448.  
  449. /* l_smtype symbol type meaning: Bit  0  1  2  3   4  5  6  7                                                     */
  450. /*                                                                        x  I  E  E   x  XTY_xx     x ==> reserved                    */
  451. /*                                                                           m  n  x                                                                                 */
  452. /*                                                                         p  t  p                                 XTY_xx's defined with    */
  453. /*                                                                           o  r  o                                 AuxEntry                                */
  454. /*                                                                             r  y  r                                                                                */
  455. /*                                                                             t     t                                                                                */
  456.  
  457. #define    L_IMPORT        0x40U                                                /* import                                         (bit  1)     */
  458. #define    L_ENTRY            0x20U                                                /* entry                                         (bit  2)     */
  459. #define    L_EXPORT        0x10U                                                /* export                                         (bit  3)     */
  460. #define    L_SMTYP(x)    ((x).l_smtype & 0x07U)            /* XTY_xx is symbol type          (bits 5-7) */
  461.  
  462. #define    LDR_EXPORT(x)    (((x).l_smtype & L_EXPORT) != 0U)    /* l_smtype field operations...    */
  463. #define    LDR_ENTRY(x)    (((x).l_smtype & L_ENTRY ) != 0U)
  464. #define    LDR_IMPORT(x)    (((x).l_smtype & L_IMPORT) != 0U)
  465.  
  466. typedef LdrExtSymEntry ldsym;                            /* for compatibility only                                            */
  467. typedef LdrExtSymEntry LDSYM;
  468. #define    LDSYMSZ    sizeof(LdrExtSymEntry)
  469.  
  470. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  471.  
  472. struct LdrRelEntry {                                            /* Loader relocation table entry layout:            */
  473.     unsigned long  l_vaddr;                                    /*         virtual address of reference to fix up    */
  474.     long                     l_symindx;                                /*         external ldr symbol table INDEX (rel. 0)*/
  475.     union {                                                                    /*         relocation type and fixup size:                    */
  476.         struct {                                                            /*                (see RelocEntry r_rtype for values)    */
  477.             unsigned char    _l_rsize;                            /*                 sign and reloc bit len                            */
  478.             unsigned char    _l_rtype;                            /*                 toc relocation type                                    */
  479.         } _l_l;
  480.         unsigned short _l_type;                                /*         relocation type(same meaning as r_rtype)*/
  481.     } _l;
  482.     short                     l_rsecnm;                                /*         section nbr being relocated (rel. 1)        */
  483. };
  484. typedef struct LdrRelEntry LdrRelEntry, *LdrRelEntryPtr;
  485.  
  486. #define l_rsize    _l._l_l._l_rsize
  487. #define l_rtype    _l._l_l._l_rtype
  488. #define l_type    _l._l_type
  489.  
  490. /* Note: l_symindx, not spelling (with an "i"), not l_symndx, since this CONFLICTS with    */
  491. /*             the same field name in the LineNbrEntry.  Also read what follows...                        */
  492.  
  493. #define L_SYMINDX_TEXT 0L                                    /* These values for l_symindx are implicit.     */
  494. #define L_SYMINDX_DATA 1L                                    /*         An index, i, for l_symindx, when i >= 3    */
  495. #define L_SYMINDX_BSS  2L                                    /*        refers to LdrExtSymEntry[i-3], where         */
  496.                                                                                     /*         LdrExtSymEntry[0] is the 1st symbol.        */
  497.  
  498. #define LDRRELOC_RSIGN(x) (((x).l_rsize & R_SIGN)) /* same as the RELOC_xxx but operates*/
  499. #define LDRRELOC_RLEN(x)    (((x).l_rsize & R_LEN))     /* on LdrRelEntry. R_SIGN and  R_LEN    */
  500. #define LDRRELOC_RTYPE(x) ((x).l_rtype)                         /* are defined for the RelocEntry.        */
  501.  
  502. typedef LdrRelEntry ldrel;                                /* for compatibility only                                            */
  503. typedef LdrRelEntry LDREL;
  504. #define    LDRELSZ    sizeof(LDREL)
  505.  
  506. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  507.  
  508.                                                                                     /* Import file ID entries (best I can do):        */
  509. #define l_impidpath(x)                                         /*         file ID pathname                                                */\
  510.     ((char *)(x))
  511. #define l_impidbase(x)                                         /*        basename                                                                */\
  512.     ((char *)(l_impidpath(x) + strlen(l_impidpath(x)) + 1))
  513. #define l_impidmem(x)                                             /*        archive file member name                                */\
  514.     ((char *)(l_impidbase(x) + strlen(l_impidbase(x)) + 1))
  515.  
  516. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  517.  
  518. struct LdrStrEntry {                                            /* String table entry layout:                                    */
  519.     unsigned short l_parmstlen;                            /*        string length    (including null)                    */
  520.     char                     l_parmst[1];                            /*        START of the string of len l_parmstlen    */
  521. };
  522. typedef struct LdrStrEntry LdrStrEntry, *LdrStrEntryPtr;
  523.  
  524. /*---------------*
  525.  | Debug Section |
  526.  *---------------*/
  527.  
  528. struct DbxStabEntry {                                            /* Debug dbx stab string entry layout:                */
  529.     unsigned short dbx_len;                                    /*        string length    (including null)                    */
  530.     char                     dbx_stabst[1];                        /*        START of the string of len dbx_len            */
  531. };                                                                                /*        (strings are null terminated)                        */
  532. typedef struct DbxStabEntry DbxStabEntry, *DbxStabEntryPtr;
  533.  
  534. /*--------------------*
  535.  | Type Check Section |
  536.  *--------------------*/
  537.  
  538. struct TypeChkEntry {                                            /* Type check entry layout:                                        */
  539.     unsigned short t_len;                                        /*        string length                                                        */
  540.     char                     t_st[1];                                    /*        START of the string of len t_len                */
  541. };                                                                                /*        (strings are NOT null terminated)                */
  542. typedef struct TypeChkEntry TypeChkEntry, *TypeChkEntryPtr;
  543.  
  544. struct AIXTypeChkEntry {                                    /* Type check entry layout used by AIX:                */
  545.     unsigned short t_len;                                        /*        string length (always 10)                                */
  546.     unsigned short t_lang;                                    /*        compiler language ID (e_lang's LANG_xx)    */
  547.     unsigned long  t_genHash;                                /*        most general hash form                                    */
  548.     unsigned long     t_langHash;                            /*        language-specific hash form                            */
  549. };
  550. typedef struct AIXTypeChkEntry AIXTypeChkEntry, *AIXTypeChkEntryPtr;
  551.  
  552. /*-------------------*
  553.  | Exception Section |
  554.  *-------------------*/
  555.  
  556. struct ExceptionEntry {                                        /* Exception entry layout:                                        */
  557.     union {                                                                    /*         use e_symndx if e_reason=0 else e_paddr    */
  558.         long e_symndx;                                                /*                 symbol tbl idx (0 rel) of funct name*/
  559.         long e_paddr;                                                    /*                 (physical) address of trap instr.     */
  560.     } e_addr;
  561.     unsigned char e_lang;                                        /*        compiler language ID code                             */
  562.     signed char         e_reason;                                    /*         exception reason code                                     */
  563. };
  564. typedef struct ExceptionEntry ExceptionEntry, *ExceptionEntryPtr;
  565.  
  566. #define e_symndx e_addr.e_symndx
  567. #define e_paddr     e_addr.e_paddr
  568.                                                                                     /* e_lang compiler language ID codes:                    */
  569.                                                                                     /* (also used by SymTblEntry's n_type n_lang)    */
  570. #define LANG_C              0x00U                                /*         C                                                                                */
  571. #define LANG_FORTRAN 0x01U                                /*         Fortran                                                                    */
  572. #define LANG_PASCAL  0x02U                                /*         Pascal                                                                    */
  573. #define LANG_ADA          0x03U                                /*         ADA                                                                            */
  574. #define LANG_PL1          0x04U                                /*         PL/1                                                                        */
  575. #define LANG_BASIC      0x05U                                /*         Basic                                                                        */
  576. #define LANG_LISP      0x06U                                /*         Lisp                                                                        */
  577. #define LANG_COBOL      0x07U                                /*         Cobol                                                                        */
  578. #define LANG_MODULA2 0x08U                                /*         Modula2                                                                    */
  579. #define LANG_CPP          0x09U                                /*         C++                                                                            */
  580. #define LANG_RPG          0x0AU                                /*         RPG                                                                            */
  581. #define LANG_PL8          0x0BU                                /*         PL8, PLIX                                                                */
  582. #define LANG_ASM          0x0CU                                /*         Assembly                                                                */
  583. #define LANG_MACOS     0x2AU                                /*         MacOS language neutral Exceptions                */
  584.  
  585. typedef ExceptionEntry exceptab;                    /* for compatibility only                                            */
  586. typedef ExceptionEntry EXCEPTAB;
  587. #define    EXCEPTSZ 6
  588.  
  589. /*-----------------*
  590.  | Comment Section |
  591.  *-----------------*/
  592.  
  593. struct CommentEntry {                                            /* Comment entry layout:                                            */
  594.     unsigned long c_len;                                        /*        comment length                                                    */
  595.     char                  c_data[1];                                /*        START of the comment of len c_len                */
  596. };                                                                                /*        (strings are NOT null terminated)                */
  597. typedef struct CommentEntry CommentEntry, *CommentEntryPtr;
  598.  
  599. /*--------------------------------------------------------------------------------------*/
  600.  
  601.                                                         /*-------------------------*
  602.                                                          | Relocation data section |
  603.                                                          *-------------------------*/
  604.  
  605. struct RelocEntry {                                                /* Relocation entry layout:                                        */
  606.     unsigned long    r_vaddr;                                    /*         virtual address of reference to fix up    */
  607.     unsigned long    r_symndx;                                    /*         symbol table index (rel 0) to get value    */
  608.     union {                                                                    /*        relocation field type                                        */
  609.         struct {
  610.             unsigned char    _r_rsize;                            /*                 sign and reloc bit len (see below)    */
  611.             unsigned char    _r_rtype;                            /*                 toc relocation type (see below)            */
  612.         } _r_r;
  613.         unsigned short _r_type;                                /*                 old style COFF relocation type             */
  614.     } _r;
  615. };
  616. typedef struct RelocEntry RelocEntry, *RelocEntryPtr;
  617.  
  618. #define r_rsize    _r._r_r._r_rsize
  619. #define r_rtype    _r._r_r._r_rtype
  620. #define r_type    _r._r_type
  621.  
  622. #define R_SIGN    0x80U                                            /* extract sign of relocation                                     */
  623. #define R_LEN        0x1FU                                            /* extract bit length field (length - 1)            */
  624.  
  625. #define RELOC_RSIGN(x) (((x).r_rsize & R_SIGN))
  626. #define RELOC_RLEN(x)     (((x).r_rsize & R_LEN))
  627. #define RELOC_RTYPE(x) ((x).r_rtype)
  628.  
  629.                                                                                     /* r_type relocation types:                                        */
  630. #define    R_POS        0x00U                                            /*        A(sym)              positive relocation                */
  631. #define R_NEG        0x01U                                            /*         -A(sym)             negative relocation                */
  632. #define R_REL        0x02U                                            /*         A(sym-$)           relative to self                        */
  633. #define    R_TOC        0x03U                                            /*         A(sym-TOC)      relative to TOC                        */
  634. #define R_TRL        0x12U                                            /*         A(sym-TOC)      TOC relative indirect load    */
  635. #define R_TRLA    0x13U                                            /*         A(sym-TOC)      TOC relative load address    */
  636. #define R_GL        0x05U                                            /*         A(ext TOC of sym) global linkage-ext TOC*/
  637. #define R_TCL        0x06U                                            /*         A(lcl TOC of sym) local TOC address         */
  638. #define R_RL        0x0CU                                            /*         A(sym)              pos indirect load (=R_POS)    */
  639. #define R_RLA        0x0DU                                            /*         A(sym)              pos load address  (=R_POS)    */
  640. #define R_REF        0x0FU                                            /*         AL0(sym)          nonrel ref-no garbge collct*/
  641. #define R_BA        0x08U                                            /*         A(sym)              br. absolute(nonmodifiable)*/
  642. #define R_RBA        0x18U                                            /*         A(sym)              br. absolute (modifiable)    */
  643. #define    R_RBAC    0x19U                                            /*         A(sym)              br. absolute constant            */
  644. #define    R_BR        0x0AU                                            /*         A(sym-$)          br. rel self(nonmodifiable)*/
  645. #define R_RBR        0x1AU                                            /*         A(sym-$)          br. rel self (modifiable)    */
  646. #define R_RBRC    0x1BU                                            /*         A(sym-$)          br. absolute constant            */
  647. #define R_RTB        0x04U                                            /*         A((sym-$)/2) not used                                        */
  648. #define R_RRTBI    0x14U                                            /*         A((sym-$)/2) not used                                        */
  649. #define R_RRTBA    0x15U                                            /*         A((sym-$)/2) not used                                        */
  650.  
  651. typedef RelocEntry reloc;                                    /* for compatibility only                                            */
  652. typedef RelocEntry RELOC;
  653. #define    RELSZ    10
  654.  
  655. /*--------------------------------------------------------------------------------------*/
  656.  
  657.                                                             /*---------------------*
  658.                                                              | Line Number Section |
  659.                                                              *---------------------*/
  660.  
  661. struct LineNbrEntry {                                            /* Line number section entry layout:                    */
  662.     union {                                                                    /*         use l_symndx if l_lnno=0 else l_paddr        */
  663.         long    l_symndx;                                                /*         symbol table index (rel 0) of funct name*/
  664.         long    l_paddr;                                                /*         physical address of line number                 */
  665.     } l_addr;
  666.     unsigned short l_lnno;                                    /*         line number (0 indicates function start)*/
  667. };
  668. typedef struct LineNbrEntry LineNbrEntry, *LineNbrEntryPtr;
  669.  
  670. #define l_symndx l_addr.l_symndx
  671. #define l_paddr     l_addr.l_paddr
  672.  
  673. typedef LineNbrEntry lineno;                            /* for compatibility only                                            */
  674. typedef LineNbrEntry LINENO;
  675. #define    LINESZ 6
  676.  
  677. /*--------------------------------------------------------------------------------------*/
  678.  
  679.                                                                     /*--------------*
  680.                                                                      | Symbol Table |
  681.                                                                      *--------------*/
  682.  
  683. struct SymTblEntry {                                            /* Symbol table entry layout:                                    */
  684.     union {
  685.         struct {
  686.             long _n_zeroes;                                            /*         0 ==> string table offset else .debug     */
  687.             long _n_offset;                                            /*         string table or .debug section offset        */
  688.         } _n_n;                                                                /*        (offset is to string, NOT its length)        */
  689.         char      *_n_nptr[2];                                        /*         allows for overlaying                                     */
  690.         char     _n_name[SYMNMLEN];                            /*         old COFF version                                                 */
  691.     } _n;
  692.     long                     n_value;                                    /*         value (storage class dependent)                    */
  693.     short                     n_scnum;                                    /*         section number (some special-see below)    */
  694.     union {
  695.         unsigned short n_type;                                /*         fundamental and derived type (see below)*/
  696.         struct {                                                            /*        when n_sclass is C_FILE n_type becomes:    */ 
  697.             unsigned char n_lang;                                /*            source language ID (e_lang's LANG_xx)    */
  698.             unsigned char n_cpuID;                            /*            cpu type ID (o_cputype's CPU_ID_xx)        */
  699.         } _n;
  700.     } _n_type;
  701.     unsigned char     n_sclass;                                /*         storage class (see below)                              */
  702.     signed char         n_numaux;                                /*         number of auxiliary entries that follow    */
  703. };
  704. typedef struct SymTblEntry SymTblEntry, *SymTblEntryPtr;
  705.  
  706. #define n_zeroes    _n._n_n._n_zeroes
  707. #define n_offset    _n._n_n._n_offset
  708. #define n_nptr        _n._n_nptr[1]
  709. #define n_name        _n._n_name
  710. #define n_type        _n_type.n_type
  711. #define n_lang        _n_type._n.n_lang
  712. #define n_cpuID        _n_type._n.n_cpuID
  713.                                                                                     /* n_scnum special section numbers:                        */
  714. #define    N_UNDEF           0                                            /*        undefined or uninited external symbol        */
  715. #define    N_ABS             -1                                            /*         absolute symbol value                                      */
  716. #define    N_DEBUG         -2                                            /*         special debugging symbol (no value)            */
  717. #define N_SCNUM            1                                            /*        any value > 0 (N_SCNUM IS NOT A VALUE)    */
  718.  
  719.                                                                                     /* n_type:                                                                        */
  720.                                                                                     /*         fundamental types (bits 4:7):                        */
  721. #define    T_NULL         0U                                            /*                 no type                                                            */
  722. #define    T_ARG             1U                                            /*                 function argument                                        */
  723. #define    T_CHAR         2U                                            /*                 char                                                                */
  724. #define    T_SHORT         3U                                            /*                 short integer                                             */
  725. #define    T_INT             4U                                            /*                 integer                                                         */
  726. #define    T_LONG         5U                                            /*                 long integer                                                */
  727. #define    T_FLOAT         6U                                            /*                 floating point                                            */
  728. #define    T_DOUBLE     7U                                            /*                 double word                                                    */
  729. #define    T_STRUCT     8U                                            /*                 struct                                                            */
  730. #define    T_UNION         9U                                            /*                 union                                                                */
  731. #define    T_ENUM        10U                                            /*                 enum                                                                */
  732. #define    T_MOE            11U                                            /*                 member of enum                                            */
  733. #define    T_UCHAR        12U                                            /*                 unsigned character                                    */
  734. #define    T_USHORT    13U                                            /*                 unsigned short                                            */
  735. #define    T_UINT        14U                                            /*                 unsigned integer                                        */
  736. #define    T_ULONG        15U                                            /*                 unsigned long                                                */
  737.  
  738.                                                                                     /*         derived types (bits 2:3):                                */
  739. #define DT_NON         0U                                            /*                 no derived type                                             */
  740. #define DT_PTR         1U                                            /*                 pointer                                                         */
  741. #define DT_FCN         2U                                            /*                 function                                                         */
  742. #define DT_ARY         3U                                            /*                 array                                                             */
  743.  
  744.                                                                                     /*         n_type manipulation macros:                            */
  745. #define N_BTMASK    0x0FU                                        /*                 extract fundamental type                         */
  746. #define N_TMASK        0x30U                                        /*                 extract derived type                                */
  747. #define N_BTSHFT    4                                                /*                 shift to access derived type                */
  748. #define BTYPE(x)    ((x) & N_BTMASK)                                                    /* extract basic type                */
  749. #define DTYPE(x)    (((x) & N_TMASK) >> N_BTSHFT)                            /* extract derived type            */
  750. #define ISPTR(x)    (((x) & N_TMASK) == (DT_PTR << N_BTSHFT)) /* is pointer ?                            */
  751. #define ISFCN(x)    (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))    /* is function ?                        */
  752. #define ISARY(x)    (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))    /* is array ?                                */
  753.  
  754.                                                                                     /* n_sclass storage classes:                                    */
  755. #define C_EFCN            0xFFU                                    /*         physical end of function          <obsolete> */
  756. #define C_NULL            0U                                        /*                                                                                     */
  757. #define C_AUTO            1U                                        /*         automatic variable                     <obsolete> */
  758. #define C_EXT                2U                                        /*         external symbol                                                    */
  759. #define C_STAT            3U                                        /*         static symbol                                                        */
  760. #define C_REG                 4U                                        /*         register variable                         <obsolete> */
  761. #define C_EXTDEF         5U                                        /*         external definition                     <obsolete> */
  762. #define C_LABEL             6U                                        /*         label                                                                        */
  763. #define C_ULABEL         7U                                        /*         undefined label                             <obsolete> */
  764. #define C_MOS                 8U                                        /*         structure member                         <obsolete> */
  765. #define C_ARG                 9U                                        /*         function argument                         <obsolete> */
  766. #define C_STRTAG     10U                                        /*         structure tag                                 <obsolete> */
  767. #define C_MOU             11U                                        /*         union member                                 <obsolete> */
  768. #define C_UNTAG         12U                                        /*         union tag                                         <obsolete> */
  769. #define C_TPDEF         13U                                        /*         type definition                             <obsolete> */
  770. #define C_USTATIC     14U                                        /*         uninitialized static                 <obsolete> */
  771. #define C_ENTAG         15U                                        /*         enumeration tag                             <obsolete> */
  772. #define C_MOE             16U                                        /*         enumeration member                     <obsolete> */
  773. #define C_REGPARM     17U                                        /*         register argument                         <obsolete> */
  774. #define C_FIELD         18U                                        /*         bit field                                         <obsolete> */
  775. #define C_BLOCK        100U                                        /*         ".bb" or ".eb"                                                    */
  776. #define C_FCN            101U                                        /*         ".bf" or ".ef"                                                    */
  777. #define C_EOS            102U                                        /*         end of structure                         <obsolete> */
  778. #define C_FILE        103U                                        /*         file name                                                                */
  779. #define C_LINE        104U                                        /*        utility program use (?)             <obsolete> */
  780. #define C_ALIAS        105U                                        /*         duplicate tag                                 <obsolete> */
  781. #define C_HIDDEN    106U                                        /*         unnamed static symbol                 <obsolete> */
  782. #define    C_HIDEXT    107U                                        /*         unnamed external symbol                                    */
  783. #define    C_BINCL        108U                                        /*         beginning of include file                                */
  784. #define    C_EINCL        109U                                        /*         end of include file                                            */
  785. #define C_INFO        110U                                        /*        special information                                            */
  786.  
  787.                                                                                     /* n_sclass dbx storage classes:                            */
  788. #define C_GSYM        0x80U                                        /*        global variable                                                    */
  789. #define C_LSYM        0x81U                                        /*        automatic variable allocated on stack        */
  790. #define C_PSYM        0x82U                                        /*        argument to subr. aloced on stack                */
  791. #define C_RSYM        0x83U                                        /*        register variable                                                */
  792. #define C_RPSYM        0x84U                                        /*        function argument in register                        */
  793. #define C_STSYM        0x85U                                        /*        statically allocated symbol                            */
  794. #define C_TCSYM        0x86U                                        /*        <reserved>                                                            */
  795. #define C_BCOMM        0x87U                                        /*        beginning of common block                                */
  796. #define C_ECOML        0x88U                                        /*        local member of common block                        */
  797. #define C_ECOMM        0x89U                                        /*        end of common block                                            */
  798. #define C_DECL        0x8CU                                        /*        declaration of object                                        */
  799. #define C_ENTRY        0x8DU                                        /*        alternate entry                                                    */
  800. #define C_FUN            0x8EU                                        /*        function or procedure                                        */
  801. #define C_BSTAT        0x8FU                                        /*        beginning of static block                                */
  802. #define C_ESTAT        0x90U                                        /*        end of static block                                            */
  803.  
  804. #define DBXMASK        0x80U                                        /*        all of these have the sign bit set            */
  805.  
  806. #define ISSTAB(x) (((x) & DBXMASK) != 0)    /* n_sclass with high bit ==> n_name stab str    */
  807.  
  808. /* Note: when the n_sclass is a C_FILE (103), the n_type represents a language ID and        */
  809. /*             CPU ID, n_lang and n_cpuID respectively. The LANG_xx's define the n_lang values*/
  810. /*             and the CPU_ID_xx's define the CPU ID values.                                                                    */
  811.  
  812. /*------------------------------*
  813.  | Auxiliary symbol table entry |
  814.  *------------------------------*/
  815.  
  816. #define    FILNMLEN 14                                                /* nbr of characters in a file name                     */
  817. #define    DIMNUM        4                                                /* nbr of array dimensions in auxiliary entry */
  818.  
  819. union AuxEntry {                                                    /* Auxiliary symbol table entry layout:                */                            
  820.     struct {                                                                /*        symbol                                                                    */
  821.         long x_tagndx;                                                /*                 file offset to exception table            */
  822.                                                                                     /*                 or struct, union, enum tag index         */
  823.         union {                                                                
  824.             struct {                                                        /*                struct, union, array info:                    */
  825.                 unsigned short x_lnno;                        /*                         declaration line number                 */
  826.                 unsigned short x_size;                        /*                         struct, union, or array size         */
  827.             } x_lnsz;
  828.             long x_fsize;                                                /*                 function size (bytes)                                */
  829.         } x_misc;
  830.         
  831.         union {                                                                /*                function,tag,.bb (additional fields)*/
  832.             struct {                                                        /*                                                                                        */
  833.                 long    x_lnnoptr;                                    /*                         file offset to line number            */
  834.                 long    x_endndx;                                        /*                         index to entry after function        */
  835.             } x_fcn;
  836.             
  837.             struct {                                                        /*                 array (additional fields)                        */
  838.                 unsigned short x_dimen[DIMNUM];        /*                        up to 4 dimensions                            */
  839.             } x_ary;
  840.         } x_fcnary;
  841.         
  842.         unsigned short x_tvndx;                                /*                 <unused> (pads up to the 18 bytes)    */
  843.     } x_sym;
  844.     
  845.     union {                                                                    /*        file name                                                                */
  846.         char x_fname[FILNMLEN];                                /*                source file name                                        */
  847.         struct {                                                            /*              or                                                                    */
  848.             long                    x_zeroes;                            /*                0 ==> string is in the string table    */
  849.             long                    x_offset;                            /*                offset to file string in string tbl    */
  850.             char                    x_pad[FILNMLEN-8];        
  851.             unsigned char    x_ftype;                            /*                file string type                                        */
  852.         } _x;
  853.     } x_file;
  854.                                                                                     /*                 x_ftype file string types:                    */
  855.     #define    XFT_FN     0U                                            /*                        source file name                                 */
  856.     #define    XFT_CT     1U                                            /*                        compile time stamp                             */
  857.     #define    XFT_CV     2U                                            /*                        compiler version number                 */
  858.     #define    XFT_CD 128U                                            /*                        compiler defined information         */
  859.     
  860.     struct {                                                                /*         section                                                                    */
  861.         long                     x_scnlen;                             /*                 section length                                            */
  862.         unsigned short x_nreloc;                             /*                 number of relocation entries                 */
  863.         unsigned short x_nlinno;                             /*                 number of line numbers                             */
  864.     } x_scn;
  865.  
  866.     struct {                                                                /*         csect                                                                        */
  867.         long                     x_scnlen;                            /*                 0, csect length, or symbol tbl index*/
  868.         long                     x_parmhash;                        /*                 .typchk sctn offset to type chk str    */
  869.         unsigned short x_snhash;                            /*                 .typchk section number (rel. 1)         */
  870.         unsigned char     x_smtyp;                                /*                 log 2 alignment (0:4) and type (5:7)*/
  871.         unsigned char     x_smclas;                            /*                 storage mapping class (see below)        */
  872.         long                     x_stab;                                /*                 dbx stab info index             (reserved)*/
  873.         unsigned short x_snstab;                            /*                 section nbr with dbx stab (reserved)*/
  874.     } x_csect;
  875.                                                                                     /*                 x_smtyp manipulation macros:                */
  876.     #define X_ALSHIFT 3                                            /*                        alignament = bits 0:4; type 5:7    */
  877.     #define X_SMTMASK 0x07U                                    /*                        mask to extract type                        */
  878.     #define X_ALIGNMENT(x) ((x)>>X_ALSHIFT)    /*                        access alignent value                        */
  879.     #define X_SMTYP(x)         ((x)& X_SMTMASK)    /*                        access csect type                                */
  880.     
  881.                                                                                     /*                 x_smtyp csect types (bits 5:7):            */
  882.     #define    XTY_ER    0U                                            /*                         external reference                             */
  883.     #define    XTY_SD    1U                                            /*                         csect definition                                 */
  884.     #define XTY_LD    2U                                            /*                         entry point label definition         */
  885.     #define XTY_CM    3U                                            /*                         common (BSS)                                         */
  886.     #define XTY_HL    4U                                            /*                        hidden label                                        */
  887.     #define XTY_EM    4U                                            /*                         error message - linker usage        */
  888.     #define XTY_US    5U                                            /*                         unset - linker usage                        */
  889.     
  890.                                                                                     /*                x_smclas storage mapping classes         */
  891.                                                                                     /*                        read only classes                                */
  892.     #define    XMC_PR     0U                                            /*                                 program code                                 */
  893.     #define    XMC_RO     1U                                            /*                                 read-only constants                 */
  894.     #define XMC_DB     2U                                            /*                                 debug dictionary table             */
  895.     #define XMC_GL     6U                                            /*                                 global linkage                            */
  896.     #define XMC_XO     7U                                            /*                                 extended operation                    */
  897.     #define XMC_SV     8U                                            /*                                 supervisor call descriptor    */
  898.     #define XMC_TI    12U                                            /*                                 traceback index csect             */
  899.     #define XMC_TB    13U                                            /*                                 traceback table csect             */
  900.                                                                                     /*                        read/write classes                            */
  901.     #define XMC_RW     5U                                            /*                                read/write data                            */
  902.     #define XMC_TC0 15U                                            /*                                 toc anchor for addressablty    */
  903.     #define XMC_TC     3U                                            /*                                 general toc entry                     */
  904.     #define XMC_DS    10U                                            /*                                 function descriptor csect        */
  905.     #define XMC_UA     4U                                            /*                                 unclassified                                */
  906.     #define XMC_BS     9U                                            /*                                 bss class                                        */
  907.     #define XMC_UC    11U                                            /*                                un-named FORTRAN common         */
  908.     #define XMC_TD    16U                                            /*                                scalar data entry in the toc*/
  909. };
  910. typedef union AuxEntry AuxEntry, *AuxEntryPtr;
  911.  
  912. #define x_tagndx      x_sym.x_tagndx
  913. #define x_lnno          x_sym.x_misc.x_lnsz.x_lnno
  914. #define x_size          x_sym.x_misc.x_lnsz.x_size
  915. #define x_fsize          x_sym.x_misc.x_fsize
  916. #define x_lnnoptr     x_sym.x_fcnary.x_fcn.x_lnnoptr
  917. #define x_endndx     x_sym.x_fcnary.x_fcn.x_endndx
  918. #define x_dimen         x_sym.x_fcnary.x_ary.x_dimen
  919. #define x_tvndx         x_sym.x_tvndx
  920. #define x_fname         x_file.x_fname
  921. #define x_zeroes     x_file._x.x_zeroes
  922. #define x_offset     x_file._x.x_offset
  923. #define x_ftype         x_file._x.x_ftype
  924. #define x_scnlen     x_scn.x_scnlen                    /* (this is also used for x_csect's x_scnlen)    */
  925. #define x_nreloc     x_scn.x_nreloc
  926. #define x_nlinno     x_scn.x_nlinno
  927. #define x_parmhash x_csect.x_parmhash
  928. #define x_snhash     x_csect.x_snhash
  929. #define x_smtyp         x_csect.x_smtyp
  930. #define x_smclas     x_csect.x_smclas
  931. #define x_stab         x_csect.x_stab
  932. #define x_snstab     x_csect.x_snstab
  933.  
  934. typedef SymTblEntry syment;                                /* for compatibility only                                            */
  935. typedef SymTblEntry SYMENT;
  936. #define    SYMESZ 18
  937.  
  938. typedef AuxEntry auxent;
  939. typedef AuxEntry AUXENT;
  940. #define    AUXESZ SYMESZ
  941. #define x_exptr    x_tagndx
  942.  
  943. /*--------------------------------------------------------------------------------------*/
  944.  
  945.                                                                 /*--------------*
  946.                                                                  | String Table |
  947.                                                                  *--------------*/
  948.  
  949. struct StringTable {                                            /* String table layout:                                                */
  950.     long st_len;                                                        /*        table length INCLUDING these 4 bytes        */
  951.     char st_table[1];                                                /*        list of C strings START here                        */
  952. };                                                                                /*        (strings are null terminated)                        */
  953. typedef struct StringTable StringTable, *StringTablePtr;
  954.  
  955. /* Note: st_len can have a value 0 to mean NO strings follow!  4 means the same thing.    */
  956. /*              Offsets into this table are to the string itself, not to the length that                */
  957. /*             precedes it.                                                                                                                                        */
  958.  
  959. /*--------------------------------------------------------------------------------------*/
  960.  
  961. #if GENERATINGPOWERPC
  962. #pragma options align=reset
  963. #endif
  964.  
  965. #endif    /* __XCOFF__ */
  966.